package com.yicong.ants.view.dialog;

import android.content.Context;
import android.view.View;
import android.widget.Toast;

import com.cchao.simplelib.core.UiHelper;
import com.cchao.simplelib.util.ConvertUtils;
import com.cchao.simplelib.util.StringHelper;
import com.yicong.ants.R;
import com.yicong.ants.utils.DisplayUtils;
import com.yicong.ants.utils.L;
import com.yicong.ants.utils.ToastUtils;
import com.yicong.ants.view.CalendarList;

/**
 * 入住和离店日期
 *
 * @author LinDingQiang
 * @description
 * @time 4/17/21 9:51 PM
 * @email dingqiang.l
 */
public class InDateDialog extends BaseNiceDialog {
    private CallBack mListener;
    private String startDate;
    private String endDate;

    public static InDateDialog newInstance(Context context) {
        InDateDialog dialog = new InDateDialog();
        dialog
                .setHeight(DisplayUtils.px2dp(context, (float) (UiHelper.getScreenHeight() * 0.9)))
                .setOutCancel(true)
                .setDimAmount(0.3f)
                .setShowBottom(true);
        return dialog;
    }

    @Override
    public int intLayoutId() {
        return R.layout.dialog_in_date;
    }

    @Override
    public void convertView(NiceViewHolder holder, BaseNiceDialog dialog) {
        CalendarList calendarList = holder.getView(R.id.calendarList);
        calendarList.setOnDateSelected((startDate, endDate) -> {
            L.i("startDate:" + startDate + ",endDate:" + endDate);
            this.startDate = startDate;
            this.endDate = endDate;
        });
        holder.setOnClickListener(R.id.btn_ok, v -> {
            if (StringHelper.isEmpty(startDate) || StringHelper.isEmpty(endDate)) {
                ToastUtils.showShort(getActivity(), "请选择入住日期和离店日期");
                return;
            }
            dialog.dismiss();
            mListener.onItemClick(startDate, endDate);
        });
    }

    public InDateDialog setConvertListener(CallBack listener) {
        this.mListener = listener;
        return this;
    }

    public interface CallBack {
        void onItemClick(String startDate, String endDate);
    }
}
